package com.chap15;

import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.YieldingWaitStrategy;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;

import java.util.concurrent.Executors;

/**
 * <p>
 * <code>DisruptorDemo</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-04-18 14:58
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
public class DisruptorDemo2 {
    public static void main(String[] args) {
        Disruptor<OrderEvent> orderEventDisruptor = new Disruptor<>(new OrderEventFactory(),
                1024 * 1024,
                Executors.defaultThreadFactory(),
                ProducerType.SINGLE, new YieldingWaitStrategy());
        orderEventDisruptor.handleEventsWith(new OrderEventHandler());
        orderEventDisruptor.start();

        RingBuffer<OrderEvent> ringBuffer = orderEventDisruptor.getRingBuffer();
        OrderEventProducer orderEventProducer = new OrderEventProducer(ringBuffer);
        for (int i = 0; i < 100; i++) {
            orderEventProducer.onData(i,"zhangsan"+i);

        }
        orderEventDisruptor.shutdown();
    }
}
